﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Users_PwdManage : System.Web.UI.Page, ICallbackEventHandler
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSThemes();
    }
    string result;
    private string _question;
    public string Question
    {
        set { _question = value; }
        get { return _question; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = BasePage.WebTitle;
        if (!HttpContext.Current.User.Identity.IsAuthenticated)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            BLL.V_CUSTOMER_AUTO bll_auto = new BLL.V_CUSTOMER_AUTO();
            Model.V_CUSTOMER_AUTO model_auto = new Model.V_CUSTOMER_AUTO();
            model_auto = bll_auto.GetModel(BasePage.GetValue(0));
            Question = model_auto.VC_PWDQUESTION;
        }
    }
    public void RaiseCallbackEvent(string eventArgument)
    {
        if(!HttpContext.Current.User.Identity.IsAuthenticated)
        {
            Response.Redirect("Login.aspx");
        }
        string[] temp = eventArgument.Split('|');
        if (temp.Length < 3) //验证原密码是否正确,本地验证,不用读ERP
        {
            result=new BLL.V_CUSTOMER().Exists(BasePage.GetValue(0), temp[1]);
            if (result.Length > 1)
            {
                result = "check|1";
            }
            else
            {
                result = "check|0";
            }                        
        }
        else
        {
            if (temp[0] == "pwd")
            {
                WEB.ERP.Service erp = new WEB.ERP.Service();
                string key = ConfigurationManager.AppSettings["CODE"].ToString();
                result ="pwd"+"|"+ erp.Customer_UpPwd(key, BasePage.GetValue(0), temp[2]);
            }
            else
            {
                if (new BLL.V_CUSTOMER().V_Customer_auto_UpQuestion(BasePage.GetValue(0), temp[1], temp[2]))
                {
                    result = "question|1";
                }
                else
                {
                    result = "question|0";
                }
            }
        }
    }
    public string GetCallbackResult()
    {
        return result;
    }
}
